<template>
  <view>
    <!-- 聊天列表 -->
    <uni-list-chat v-for="item in UserList" :key="item.id" :avatar-circle="true" :title="item.name" :avatar="item.img"
      :note="JSON.parse(item.message_last)[0].content" :time="item.time" link="navigateTo"
      @click="toChatBox(item.name,item.id)">
    </uni-list-chat>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        UserList: [] //用户聊天列表
      };
    },
    onLoad() {
      this.getUserList()
    },
    methods: {
      //网络请求用户聊天列表
      async getUserList() {
        // data 重命名为 res
        const {
          data: res
        } = await uni.$http.get(
          '/bbm/message/getFriends/opOk448DzwzvqxGa_f3Ccu6VSXRg'
        ) 
        //打印请求信息
		console.log("这是res")  
        console.log(res)
        //将请求的用户列表赋值
        this.UserList = res.data
      },
      //跳转对用用户的聊天室
      toChatBox(userName, userId) {
        uni.navigateTo({
          url: "/subpkg_chatRoom/chatRoom/chatRoom?name=" + userName + "&id=" + userId
        })
      }
    }

  }
</script>

<style lang="scss">
  .chat-custom-right {
    flex: 1;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    align-items: flex-end;
  }

  .chat-custom-text {
    font-size: 12px;
    color: #999;
  }
</style>